package blockchain

import (
	"context"

	"private-domain-overseas-service/admin/business/api/internal/svc"
	"private-domain-overseas-service/tools/ent"
	"private-domain-overseas-service/tools/ent/predicate"
)

type BlockchainWalletRecordDao struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBlockchainWalletRecordDao(ctx context.Context, svcCtx *svc.ServiceContext) *BlockchainWalletRecordDao {
	return &BlockchainWalletRecordDao{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// GetBlockchainWalletRecords 根据条件查询区块链钱包记录
func (d *BlockchainWalletRecordDao) GetBlockchainWalletRecords(cond []predicate.HzBlockchainWalletRecord, current, pageSize int64) ([]*ent.HzBlockchainWalletRecord, int64, error) {
	query := d.svcCtx.Orm.HzBlockchainWalletRecord.Query().Where(cond...)

	total, err := query.Count(d.ctx)
	if err != nil {
		return nil, 0, err
	}

	records, err := query.
		Offset(int((current - 1) * pageSize)).
		Limit(int(pageSize)).
		All(d.ctx)
	if err != nil {
		return nil, 0, err
	}

	return records, int64(total), nil
}
